﻿using System;
using System.IO;
using CRC32c;

namespace APBR_Patch_Mirror
{
    class Sanity
    {
        public static string log = ""+DateTime.Now.Month + "-" + DateTime.Now.Day + "-" + DateTime.Now.Year + ".Log";
        public static string time = DateTime.Now + "";
        public static void CheckLauncher(string filePath)
        {
            Crc32 crc32 = new Crc32();
            using (FileStream f = File.Open(filePath, FileMode.Open)) crc32.ComputeHash(f);
            long crc = crc32.CrcValue;
            if (crc == MainForm.Launcher._LauncherFiles[MainForm.i].Crc)
            { }
            else
            {
                File.AppendAllText(log, time + "    Sanity Check: FAILED    " + "\"" + filePath + "\"  " + MainForm.Launcher._LauncherFiles[MainForm.i].Crc + Environment.NewLine);
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.Write("Sanity Check: ");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("FAILED                   ");
                Console.ForegroundColor = ConsoleColor.White;
            }
        }

        public static void CheckClient(string filePath)
        {
            Crc32 crc32 = new Crc32();
            using (FileStream f = File.Open(filePath, FileMode.Open)) crc32.ComputeHash(f);
            long crc = crc32.CrcValue;
            if (crc == MainForm.Client._ClientFiles[MainForm.i].Crc)
            { }
            else
            {
                File.AppendAllText(log, time + "    Sanity Check: FAILED    " + "\"" + filePath + "\"  " + MainForm.Client._ClientFiles[MainForm.i].Crc + Environment.NewLine);
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.Write("Sanity Check: ");
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("FAILED                   ");
                Console.ForegroundColor = ConsoleColor.White;
            }
        }
    }
}
